<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
$id=$_POST['id'];
$admin = new admin();
$admin->canView($_SERVER['PHP_SELF']);
$rows=$admin->getBlogPosts();


?>

<div class="oneem">
<div class="qt-tab-wrapper" style="height:90%;">
<ul class="qt">
    <li><a href="#st1-pages" id="st1" class="qta">Posts</a></li>
    <li><a href="#st2-pages" id="st2" class="qta">Edit Post</a></li>
</ul>
<div id="st1-pages" class="qt-content-container" style="display:none;">

<div style="float:left;width:48%;">
	<h2>Add new blog post</h2>
    <form class="inline" action="/admin/resources/php/requests/actions/add-blog-post.php">
    <input type="hidden" class="settings" value='{"buttonWaitingValue":"Adding post","updateNode":"#response"}' />	
    	<label>Post title:</label>
        <input type="text" class="comment-field req" name="post_title" id="post_title" />
        <p class="hint">The title of the blog post</p>
        <!--
        <label>Author:</label>
        <input type="text" class="comment-field req" name="post_author" id="post_author" />
         <p class="hint">The author of the blog post</p>
         -->
        <textarea name="post_content" id="post_content"></textarea> 
         <input type="submit" class="button" value="Add blog post" />
    </form>
</div>
<div style="float:right;width:48%;">
	<h2 class="form-heading">Current blog posts</h2>
<table width="99%" class="headed-table">
<thead>
<tr valign="top">
<td width="1%" class="hleft"></td>
<td width="45%"><h6>&nbsp;Blog title</h6></td>
<td width="35%"><h6>&nbsp;Date</h6></td>
<td width="5%" class="hright"></td>
</tr>
</thead>
<tbody>
<?php
$i=0;
foreach($rows['results'] as $row) {
$bg=($i%2) ? ' odd' : '';
echo('<tr valign="top">');//class="'.trim($bg).'"
			echo('<td class="left'.$bg.'" width="1%"><a href="/admin/resources/php/requests/actions/delete-blog-post.php?id='.(string)$row['_id'].'" class="delete-page tip" title="Delete this page"><img src="/admin/resources/images/cancel.png" /></a></td>');
			echo('<td class="'.trim($bg).'" width="45%"><strong>'.$row['heading'].'</strong></td>');
			echo('<td class="'.trim($bg).'" width="35%">'.date("d/m/y \@ G:i",$row['timestamp']).'</td>');
			echo('<td class="right'.$bg.'" width="5%" style="text-align:right;"><a href="/admin/resources/php/requests/forms/edit-blog-post.php?id='.(string)$row['_id'].'" class="blog-post-edit"><img src="/admin/resources/images/b_edit.png" /></a></td>');
		echo('</tr>');
		$i++;

}
?>
</tbody>
</table>
</div>
<div class="clearfix"></div>
</div>
<div id="st2-pages" class="qt-content-container" style="display:none;"><div id="edit-blog-post"><h2>Please choose some content to edit first</h2></div></div>

</div>
</div>
<script>
$("#post_content").wysiwyg({css: '/admin/resources/client/bundle.css',initialContent:'My blog post'});
$("#st1").click();
</script>